package com.example.demo.test;


import cn.hutool.core.bean.BeanUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * 开始工序
 */
@Slf4j
public class StartWorkProcess extends DeviceAbstractWorkProcess {


    public StartWorkProcess(String name, String description) {
        super(name, description);
    }

    @Override
    public Material working() {
        //开始加工

        log.info("工艺:"+getProcessName()+" 加工进行");


        return null;
    }

    @Override
    public WorkProcess nextProcess() {
        Map<String,Object> map = new HashMap<>();
        Material material = this.getMaterial();
        Material old = new Material();
        BeanUtil.copyProperties(material,old);
//        map.putAll(material.getAttributes());
//        map.putAll(this.getParameters());
        //TODO
        try {
            sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if(getRuler() != null){
            WorkProcess nextProcess = getRuler().getNextProcess(map);
            log.info("工艺:"+getProcessName()+" 下一个工艺:" + ((AbstractWorkProcess)nextProcess).getProcessName());
            //物料传到下个工序
            nextProcess.addMaterial(old);
            setMaterial(null);
            return nextProcess;
        }

        return null;
    }


}
